<?php
/*==========================================================================*\
| AGRIVIET - CONTENT MANAGERMENT SYSTEM						
\*==========================================================================*/

	//Xoa nhieu fan tu cung 1 luc
	if (isset($_POST['ButDel'])) {
		$cnt=0;
		foreach ($_POST['chk'] as $id)
		{			

				$result = mysql_query("delete from product where id='".$id."'");
			
				if ($result) {
					$cnt++;		
			}
		}
		echo "<script>window.location='./?act=product'</script>";
	}
	
	//Chuyen Download qua danh muc khac
	if (isset($_POST['move'])) {
		$cnt=0;
		foreach ($_POST['chk'] as $id)
		{			

				$result = mysql_query("UPDATE product set catid=".$_POST['catid']." where id='".$id."'");
				if ($result) {
					$cnt++;		
			}
		}
		echo "<script>window.location='./?act=product'</script>";
	}
	
		
 if($_GET['code']==1) echo '<div class="blue">Đã cập nhật thành công</div>'; ?>
<form method="POST" name="frmList" action="index.php"><table border="1" cellpadding="2" style="border-collapse: collapse" bordercolor="#D5E2FF" width="100%" id="AutoNumber1">
  <tr>
    <td height="25" colspan="7" align=left class="xtitle">Products</td>
    </tr>
  <tr>
    <td align=center class="title"><input type="checkbox" name="chkall" onclick="chkallClick(this);"></td>
    <td align=left class="title" >Title</td>
    <td align="left" nowrap class="title">Category </td>
    <td align="center" nowrap class="title">Price</td>
    <td align="center" nowrap class="title">Published</td>
    <td align="center" nowrap class="title">Type</td>
    <td align="center" nowrap class="title">Date</td>
    </tr>
<?php
	$sql="select * from product";
	$sql.=" order by date_add DESC";
	$result=mysql_query($sql);
	$total_records=mysql_num_rows($result);
	$record_per_page=10;
	$scroll=5;
	$page=new Page(); ///creating new instance of Class Page
	$page->set_page_data($urllink,$total_records,$record_per_page,$scroll,true,true,true);
	$page->set_qry_string();
	if($result=mysql_query($page->get_limit_query($sql))){
	$i=0;
	while($row=mysql_fetch_object($result)){
	$i++;
	if ($i%2) $class="le"; else $class="chan";
?>
  <tr class="<?=$class;?>">
    <td align="center">

    <input type="checkbox" name="chk[]" value="<? echo $row->id; ?>"></td>
    <td align="left" >
	<a href="index.php?act=<?=$_GET['act'];?>_m&id=<? echo $row->id; ?>">
	<b><? echo $row->title; ?></b></a></td>

    <td align="left" ><?
	$cat = getCat($row->catid,'product_categories');
	echo $cat->title;
	if($cat->title=='') echo "Danh mục gốc";
	?></td>
    <td align="center" ><? echo $row->price; ?></td>
    <td align="center" >
	<img src="../images/<? echo $row->published; ?>.png" /></td>
    <td align="center" >
	<? if($row->type==0){?>
	<span style="color:#FF0000">Ngành nông nghiệp</span>
	<? } else { ?>
	<span style="color:#0000FF">Ngành thực phẩm</span>
	<? } ?>
	</td>
    <td align="center" ><? echo date('d - M - Y',$row->date_add); ?></td>
    </tr>

  <?
	}
}
  ?>
</table>

 <input type="hidden" name="act" value="product">
<table border="0" width="100%" cellspacing="0" cellpadding="0" id="table1">
	<tr>
		<td width="50%">

<input type="submit" value="Delete" name="ButDel" onclick="return confirm('B&#7841;n có ch&#7855;c ch&#7855;n mu&#7889;n xoá ?');" class="button">

<input name="ButGood" type="submit" class="button" id="ButGood" value="Feature" />
 <input name="new" type="button" id="new" value="Add new" onclick="window.location='index.php?act=<?=$_GET['act'];?>_m'" class="button" />
 <input name="move" type="submit" id="move" value="Move" class="button" />&nbsp;
<select size="1" name="catid">
        <?
		echo "<option value='0'>Root</option>";
		$cats=getListCat('','product_categories');
		foreach ($cats as $cat)
		{
			if ($cat[0]==$catid)
				echo "<option value=".$cat[0]." selected>".$cat[1]."</option>";
			else
				echo "<option value=".$cat[0].">".$cat[1]."</option>";
		}
		?>
      </select>
 </td>
        <td width="50%" align="right"><div id="pagenav"><?=$page->get_page_nav();?></div></td>
	</tr>
	<tr>
	  <td colspan="2">&nbsp;</td>
    </tr>
</table>
</form>